//
//  ElecStartOrCheckVC.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/11/28.
//
// 【首页-电子台账】电子台账-待确认/查看

import Foundation
import UIKit

class ElecStartOrCheckVC: SubLevelViewController {
    var modal: StandingBookTypeModal!
    
    var param: StandingBookCommonParam = StandingBookCommonParam()
    
    init(withModal _modal: StandingBookTypeModal) {
        super.init(nibName: nil, bundle: nil)
        self.modal = _modal
        self.param.bookType = _modal.typeValue
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        title = "协同人"
        view.backgroundColor = .bg
        navigationController?.navBarStyle(.white)
        
        if deptName == nil {
            deptName = BSUser.currentUser.deptName
            deptId = BSUser.currentUser.deptId
        }
        
        reloadData()
    }
    
    func reloadData() {
        /// 检测
        API.getCheckHs(withParam: param) { responseModel in
            if let m = responseModel.model {
                if m.status == "0" {
                    self.addStartChild()
                } else {
                    self.addCheckChild(withHs: m)
                }
            }
        }
    }
    
    func removeAll() {
        view.removeAllSubViews()
    }
    
    func addStartChild() {
        removeAll()
        
        let startV = ElecStartVC(withModal: modal)
        addChild(startV)
        view.addSubview(startV.view)
        startV.view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
    }
    
    func addCheckChild(withHs hsModal: CheckHsModal) {
        removeAll()
        
        let checkV = ElecCheckVC(withModal: hsModal)
        addChild(checkV)
        view.addSubview(checkV.view)
        checkV.view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
    }
}
